home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Data 2002 May / CD Rom Data Mayıs 2002.iso / Freeware / Blitz Basic / data1.cab / Support / help / samples / tilemap.bb < prev    next >
Encoding:
Text File  |  2002-04-10  |  2.0 KB  |  100 lines

  1. ; verified 1.48 4/18/2001
  2.     
  3. Const width=640,height=480
  4. Const map_width=96,map_height=48
  5.  
  6. Global tiles
  7. Dim map(map_width,map_height)
  8.  
  9. Graphics 640,480
  10. SetBuffer BackBuffer()
  11.  
  12. CreateTiles()
  13. CreateMap()
  14. stars=LoadImage( "graphics/stars.bmp" )
  15. max_x=map_width*32-width
  16. max_y=map_height*32-height
  17.  
  18. While Not KeyDown(1)
  19.  
  20.     If KeyDown( 203 )
  21.         scroll_x=scroll_x-8:If scroll_x<0 Then scroll_x=0
  22.     Else If KeyDown( 205 )
  23.         scroll_x=scroll_x+8:If scroll_x>max_x Then scroll_x=max_x
  24.     EndIf
  25.     If KeyDown( 200 )
  26.         scroll_y=scroll_y-8:If scroll_y<0 Then scroll_y=0
  27.     Else If KeyDown( 208 )
  28.         scroll_y=scroll_y+8:If scroll_y>max_y Then scroll_y=max_y
  29.     EndIf
  30.     
  31.     Cls
  32.     TileBlock stars,-scroll_x/2,-scroll_y/2
  33.     RenderMap( scroll_x,scroll_y )
  34.     Flip
  35. Wend
  36.  
  37. End
  38.  
  39. Function RenderMap( x_offset,y_offset )
  40.     ty=y_offset/32
  41.     sy=-(y_offset Mod 32)
  42.     While sy<height
  43.         ty=ty Mod map_height
  44.         tx=x_offset/32
  45.         sx=-(x_offset Mod 32)
  46.         While sx<width
  47.             DrawImage tiles,sx,sy,map( tx Mod map_width,ty )
  48.             tx=tx+1:sx=sx+32
  49.         Wend
  50.         ty=ty+1:sy=sy+32
  51.     Wend
  52. End Function
  53.  
  54. Function CreateMap()
  55.     Color 255,255,255
  56.     Rect 0,0,map_width,map_height
  57.     Color 0,0,0
  58.     Rect 1,1,map_width-2,map_height-2
  59.     Color 255,255,255
  60.     Text map_width/2,map_height/4,"YEEEHHHAAA!",1,1
  61.     Text map_width/2,map_height/2,"ALLRIGHTY!",1,1
  62.     Text map_width/2,map_height*3/4,"TILEMAPDEMO",1,1
  63.     For x=0 To map_width-1
  64.         For y=0 To map_height-1
  65.             GetColor x,y
  66.             If ColorRed()>0 Then map(x,y)=0 Else map(x,y)=1
  67.         Next
  68.     Next
  69. End Function
  70.  
  71. Function CreateTiles()
  72.     tiles=CreateImage( 32,32,2 )
  73.     
  74.     Color 128,128,128
  75.     Rect 0,0,32,32
  76.     Color 192,192,192
  77.     Rect 0,0,31,1:Rect 0,0,1,31
  78.     Color 32,32,32
  79.     Rect 31,1,1,31:Rect 1,31,31,1
  80.     
  81.     GrabImage tiles,0,0,0
  82.     
  83.     Color 0,0,0
  84.     Rect 0,0,32,32
  85.     For k=7 To 31 Step 16
  86.         Color 192,192,192
  87.         Rect k,0,1,32
  88.         Color 32,32,32
  89.         Rect k+1,0,1,32
  90.     Next
  91.     For k=7 To 31 Step 16
  92.         Color 192,192,192
  93.         Rect 0,k,32,1
  94.         Color 32,32,32
  95.         Rect 0,k+1,32,1
  96.     Next
  97.     
  98.     GrabImage tiles,0,0,1
  99.     
  100. End Function